package com.cms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.cms.common.StringUtils;
import com.cms.dao.mapper.PlaySettingMapper;
import com.cms.model.TrLotteryPlayInfo;
import com.cms.redis.RedisService;
import com.cms.service.PlaySettingService;
import com.cms.service.ReportService;

@Component
public class PlaySettingServiceImpl implements PlaySettingService {

	@Autowired
	private PlaySettingMapper palySettingMapper;

	@Autowired
	private ReportService reportService;

	@Override
	public void updatePlayGroupStatus(int playGroupId, String status) throws Exception {
		Map<String, Object> group = new HashMap<String, Object>();
		group.put("groupId", playGroupId);
		group.put("status", status);
		this.palySettingMapper.updatePlayGroupStatus(group);
		List<Map> result = this.reportService.getReportResult("queryLotteyByGroupId", group);
		if (result != null && !result.isEmpty()) {
			for (Map<String, Object> data : result) {
				RedisService.getRedisService().del(StringUtils.obj2String(data.get("hash")));
			}
		}
	}

	@Override
	public void updatePlayInfo(Map<String, Object> play) throws Exception {
		this.palySettingMapper.updatePlayInfo(play);
		StringBuilder sb = new StringBuilder();
		sb.append("playGroupBo:").append(play.get("groupId"));
		RedisService.getRedisService().del(sb.toString());// 删除玩法组的缓存数据
	}

	@Override
	public void updatePlayStatus(int palyId, String status, int groupId) throws Exception {
		Map<String, Object> play = new HashMap<String, Object>();
		play.put("playId", palyId);
		play.put("status", status);
		this.palySettingMapper.updatePlayStatus(play);
		// if(StringUtils.equalsIgnoreCase("N", status))//删除
		{
			StringBuilder sb = new StringBuilder();
			sb.append("playGroupBo:").append(groupId);
			RedisService.getRedisService().del(sb.toString());// 删除玩法组的缓存数据
		}
	}

	@Override
	public TrLotteryPlayInfo getPlayInfo(int playId) throws Exception {
		return this.palySettingMapper.getPlayInfo(playId);
	}

	@Override
	public void updateLotteryPlay(TrLotteryPlayInfo info) throws Exception {
		this.palySettingMapper.updateLotteryPlay(info);
		StringBuilder sb = new StringBuilder();
		sb.append("playGroupBo:").append(info.getLotteryGroupId());
		RedisService.getRedisService().del(sb.toString());// 删除玩法组的缓存数据
	}

}
